package com.aim.analysis.records;

import com.aim.analysis.artifact.ExperimentDate;
import com.aim.azure.AzureConnection;
import com.aim.azure.AzureGameRecordEntity;
import junit.framework.TestCase;
import sun.reflect.Reflection;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;
import java.util.List;

/**
 * User: Avraham Shvartzon
 * Date: 2/1/15
 */
public class TableDump extends TestCase{

    public static enum Table{
        GAME_RECORDS("GameMessageDate");

        final String prefix;

        private Table(String prefix) {
            this.prefix = prefix;
        }
    }

    public void testDumpGameRecord() throws Exception {
        File dumpFile = new File("C:\\temp\\game1.txt");
        ExperimentDate date = ExperimentDate.E_2015_01_15;
        dump(dumpFile, date, Table.GAME_RECORDS);

    }

    private void dump(File dumpFile, ExperimentDate date, Table table) throws Exception {
        PrintWriter pw = new PrintWriter(dumpFile);
        String delimiter = "\t";
        AzureConnection azureConnection = new AzureConnection();
        azureConnection.connect();

        Field[] declaredFields = AzureGameRecordEntity.class.getDeclaredFields();
        for (Field declaredField : declaredFields) {
            pw.print(declaredField.getName() + delimiter);
        }
        pw.println();
        azureConnection.addExperimentDate(date.tableSuffix);
        List<AzureGameRecordEntity> gameRecords = azureConnection.getGameRecords();
        for (AzureGameRecordEntity gameRecord : gameRecords) {
            for (Field declaredField : declaredFields) {
                pw.print(declaredField.get(gameRecord) + delimiter);
            }
            pw.println();
        }
        pw.close();

    }


}
